package com.ocgs.base.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class DatabaseUtil {

	private static final Log log = LogFactory.getLog(DatabaseUtil.class.getName());

	private static Map<String, String> sqlTypesMap = new HashMap<String, String>();

	static {
		Field[] fields = java.sql.Types.class.getDeclaredFields();
		for (Field item : fields) {
			try {
				String name = item.getName();
				String value = item.get(java.sql.Types.class).toString();

				log.debug("value===name: " + value + "===" + name);
				sqlTypesMap.put(value, name);
			} catch (IllegalArgumentException e) {
				log.error("IllegalArgumentException", e);
			} catch (IllegalAccessException e) {
				log.error("IllegalAccessException", e);
			}
		}
	}

	public static String getJDBCType(int type) {
		return sqlTypesMap.get(type + "");
	}

}
